<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="折扣体系名称"
          hasFeedback >
          <a-input placeholder="请输入折扣体系名称" v-model="discountSystemName" />
        </a-form-item>
     <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注"
          hasFeedback >
        
		  <a-textarea placeholder="请填写你的备注" :rows="4"  v-model="remark" style="width: 300px;"/>
        </a-form-item>


<!-- 
      <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="折扣范围"
          hasFeedback >
          <a-input placeholder="请输入折扣范围开始金额" v-model="RangeStart"    />
           <a-input placeholder="请输入折扣范围结束金额"  v-model="RangeEnd"   />
        </a-form-item> -->

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
import { deleteAction, getAction, putAction, postAction, downFile, getFileAccessHttpUrl } from '@/api/manage'
  export default {
    name: "JeecgDemoModal",
    data () {
      return {
		  remark:'',
		  discountSystemName:'',
		  RangeStart:'',
		  RangeEnd:'',
		  id:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/Discount/adddiscountSystem",
          edit: "/Discount/adddiscountSystem",
		  detail:"/Discount/getdiscountSystemdetail",
		  update:"/Discount/updatediscountSystem"
        },
      }
    },
    created () {
    },
    methods: {
		
		getdetail(id){
			getAction(this.url.detail,{id:id}).then((res)=>{
			  if(res.success){
			 this.discountSystemName=res.result.discountSystemName;
			    this.remark=res.result.remark;
			 
			  }else{
			    that.$message.warning(res.message);
			  }
			})
		},
		
      add () {
        this.edit({});
      },
      edit (record) {
		 this.id=record;
		 if( this.id!=0){
			 this.getdetail(this.id);
		 }else{
			 this.discountSystemName='';
			  this.remark='';
		 }
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
		      //时间格式化
          this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(this.id==0){
              httpurl+=this.url.add;
              method = 'get';
            }else{
              httpurl+=this.url.update;
               method = 'post';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
           formData['discountSystemName']=this.discountSystemName;
              formData['remark']=this.remark;
			    formData['id']=this.id;
         
            getAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('aaa');
                that.searchQuery();
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>